#!/bin/bash
# 仅还原 /home /opt /var
set -e

# 目录映射表：原始路径 -> 只读底图路径
declare -A MAP=(
    ["/home"]="/data/real_home"
    ["/opt/apps"]="/data/real_opt_apps"
    ["/usr/lib/dpkg"]="/data/real_usr_lib_dpkg"
    ["/usr/lib/dpkg-db"]="/data/real_usr_lib_dpkg_db"
)

# 1. 首次：若底图为空，则复制现有内容进去
for TARGET in "${!MAP[@]}"; do
    LOWER="${MAP[$TARGET]}"
    sudo mkdir -p "$LOWER"
    if [[ -z "$(ls -A "$LOWER" 2>/dev/null)" ]]; then
        echo "首次复制 $TARGET -> $LOWER ..."
        sudo rsync -a "$TARGET/" "$LOWER/"
    fi
done

